package com.framework.network.interceptor

import android.content.Context
import com.framework.network.utils.NetworkBreakException
import com.framework.network.utils.NetworkUtil
import okhttp3.Interceptor
import okhttp3.Response

/**
 * @Description:设置网络状态拦截器
 * @Author: you
 */
class NetworkStatusInterceptor(private val context: Context) : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val isConnected = NetworkUtil.isNetworkAvailable(context)
        return if (isConnected) {
            chain.proceed(chain.request())
        } else {
            throw NetworkBreakException()
        }
    }
}